package com.mkb.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mkb.dao.UserDetailFamilyDAO;
import com.mkb.entity.UserDetailFamilyDO;
import com.mkb.entity.UserDetailFamilyDTO;
import com.mkb.service.UserDetailFamilyService;
import com.mkb.utils.MapUtils;
import com.zz.common.util.ObjectUtils;
import com.zz.common.validator.Assert;
import com.zz.common.validator.ValidatorUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserDetailFamilyServiceImpl implements UserDetailFamilyService {
	@Autowired
	private UserDetailFamilyDAO userDetailFamilyDAO;

	@Override
	public Boolean deleteById(Long id) {
		userDetailFamilyDAO.deleteById(id);
		return true;
	}

	@Override
	public Boolean create(UserDetailFamilyDTO record) throws Exception {
		UserDetailFamilyDO entity = record.clone(UserDetailFamilyDO.class);
		userDetailFamilyDAO.insert(entity);
		return true;
	}

	@Override
	public UserDetailFamilyDTO getById(Long id) throws Exception{
		Assert.isNull(id, "id 不能为空");
		UserDetailFamilyDO entity= userDetailFamilyDAO.getById(id);
		Assert.isNull(entity, "对象不存在");
		UserDetailFamilyDTO dto = entity.clone(UserDetailFamilyDTO.class);
		return dto;
	}

	@Override
	public Boolean update(UserDetailFamilyDTO record) throws Exception {
		Assert.isNull(record, "对象不存在");
		Assert.isNull(record.getId(), "对象id不存在");
		UserDetailFamilyDO entity = record.clone(UserDetailFamilyDO.class);
		userDetailFamilyDAO.update(entity);
		return true;
	}

	@Override
	public PageInfo<UserDetailFamilyDTO> queryPage(UserDetailFamilyDTO UserDetailFamilyDTO) throws Exception {
		ValidatorUtils.validateProperty(UserDetailFamilyDTO, "pageNum", "pageSize");
		PageHelper.startPage(UserDetailFamilyDTO.getPageNum(), UserDetailFamilyDTO.getPageSize());
		List<UserDetailFamilyDO> UserDetailFamilyDOS = userDetailFamilyDAO.queryList(MapUtils.parseMap(UserDetailFamilyDTO));
		List<UserDetailFamilyDTO> UserDetailFamilyDTOList = ObjectUtils.convertList(UserDetailFamilyDOS, UserDetailFamilyDTO.class);
		return new PageInfo<>(UserDetailFamilyDTOList);
	}

	@Override
	public List<UserDetailFamilyDTO> queryList(UserDetailFamilyDTO UserDetailFamilyDTO) throws Exception {
		List<UserDetailFamilyDO> UserDetailFamilyDOS = userDetailFamilyDAO.queryList(MapUtils.parseMap(UserDetailFamilyDTO));
		List<UserDetailFamilyDTO> UserDetailFamilyDTOList = ObjectUtils.convertList(UserDetailFamilyDOS, UserDetailFamilyDTO.class);
		return UserDetailFamilyDTOList;
	}

	@Override
	public void createBatch(List<UserDetailFamilyDTO> userDetailFamilyList) throws Exception {
		userDetailFamilyDAO.insertBatch(ObjectUtils.convertList(userDetailFamilyList, UserDetailFamilyDO.class));
	}

	@Override
	public void deleteByGraphId(Long graphId) throws Exception {
		userDetailFamilyDAO.deleteByGraphId(graphId);
	}

}